<template>
  <van-nav-bar
    title="生成订单"
    left-text="返回"
    left-arrow
    @click-left="
      () => {
        $router.push('/home/cart');
      }
    "
    fixed
  />

  <div style="margin-top: 50px"></div>

  <div>
    <p> 您的订单已经生成 {{ orderdata.product_code }}</p>
    <p> 用户名为 {{ orderdata.username }}</p>
    <p> 总结为 {{orderdata.totalPrice/100}}</p>
  </div>

  <van-submit-bar :price="orderdata.totalPrice" button-text="提交订单" @submit="onSubmit" />
</template>

<script setup>
import { useRoute } from "vue-router";
let route = new useRoute();
import { OrderDetailApi } from "@/api/api";
import { ref } from "vue";
// 自定义订单数据

import { useCounterStore } from "@/store/cart";
const store = useCounterStore();
let orderdata = ref([]);

OrderDetailApi(route.params.orderid).then((res) => {
  console.log("订单数据", res);
  orderdata.value = res.data.data;


  paydata.value={
    orderId:res.data.data.orderId,
    subject:res.data.data.product_code,
    totalPrice:res.data.data.totalPrice/100
  }
});

import { payApi } from "@/api/api";
let paydata=ref({
    orderId:'',
    subject:'',
    totalPrice:0
})

const onSubmit=()=>{
    console.log(paydata.value);
    payApi(paydata.value).then(res=>{
        window.open(res.data.data,'_blank')
    })
    
}
</script>

<style lang="scss" scoped>
</style>